<template>
	<div class="collocate-wrap">
    <ul class="collocate-wrap-box">
      <van-list v-model="loading"
                  :finished="finished"
                  finished-text=""
                  @load="onLoad"
                  :offset="offset"
                  :immediate-check="immediateCheck">
        <li class="collocate-wrap-box-item" v-for="items in collocateList" :key="items.assort_id">
          <div class="collocate-wrap-box-item-msg">
            <div class="pritit">
              <div class="pritit-title">{{items.title}}</div>
              <div class="btn">
                <div class="btn-buy" @click="navToCollcateDetail(items.assort_id, items.item[0].item_id)">立即抢购</div>
              </div>
            </div>
            <div class="pritit-price">
              <span>原价：&yen;{{items.original_price}}</span>
              <span>现价：<span class="price" v-html="scaleGoodsPriceFn(items.price, 'nowprice')"></span></span>
              <span>立省：<i>&yen;</i><em>{{items.price_spread}}</em></span>
            </div>
          </div>
          <div class="collocate-wrap-box-item-img" v-if="items.item">
            <ul>
              <li v-for="(imgSrc,index) in items.item.slice(0,3)" :key="imgSrc.item_id+index"><img :src="imgSrc.image" alt=""></li>
            </ul>
            <div class="item-count" v-if="items.item.length > 3">
              <span>共<em>{{items.item.length}}</em>件</span>
              <span @click="navToCollcateDetail(items.assort_id, items.item[0].item_id)"><img src="https://img.wifenxiao.com/h5-wfx/images/collocate-more.png" alt=""></span>
            </div>
          </div>
        </li>
      </van-list>
    </ul>
  </div>
</template>

<script>
  /**
   * @Author: yqe@360shop.cn
   * @Date: 2019-12-19 10:59:00
 * @Last Modified by: zhangmeng
 * @Last Modified time: 2020-07-02 17:59:09
   */
  
  import Vue from 'vue'
  import { List } from 'vant'
  Vue.use(List)
  
  import CountPlug from '@/components/CountPlug'
  import { scaleGoodsPrice } from '@/utils/index.js'
  import { getComboList } from '@/api/item/activity.js'
  export default Vue.extend({
    name: 'index',
    components: {
      CountPlug
    },
    data() {
      return {
        formData: {
          addNum: 1
        },
        loading: false,
        finished: false,
        offset: 20,
        immediateCheck: false,
        p: 1,
        collocateList: []
      }
    },
    mounted() {
      this.getComboListFun()
    },
    methods: {
      /**
       * 商品价格 整数放大
       */
      scaleGoodsPriceFn(price, className) {
        return scaleGoodsPrice(price, className)
      },
      /**
       * 点击tab
       */
      handleClickEvent(name) {
        // console.log(name)
      },

      /**
       * 跳转详情
       */
      navToCollcateDetail(aid, id) {
        this.$JumpPath(this, 'item-collocate-detail', { 'aid': aid, 'id': id })
      },

      onLoad() {
        setTimeout(() => {
          this.getComboListFun()
        }, 500)
      },

      /**
       * 获取搭配套餐列表
       */
      getComboListFun(onload) {
        if (onload == 1) {
          this.p = 1
          this.collocateList = []
        }
        const data = {
          p: this.p
        }
        if (this.finished) return false
        this.$loadingWrap.show()
        setTimeout(() => {
          this.$loadingWrap.close()
        }, 10000)
        getComboList(data).then(res => {
          this.loading = false
          this.$loadingWrap.close()
          if (res.status === 1) {
            const collocate = res.data.data
            if (collocate && collocate.length) {
              var length = collocate.length
            } else {
              this.finished = true
              return
            }
            if (length < 10) this.finished = true
            this.collocateList = this.collocateList.concat(collocate)
            this.p += 1
            // this.collocateList = res.data.data
          }
        })
      }
    }
  })
</script>

<style lang="scss">
  @import "src/styles/mixin";
  @import "src/styles/variables";
  .collocate-wrap{
    width: 100%;
    padding: 20px 25px;
    box-sizing: border-box;
    &-box {
      &-item {
        width: 100%;
        padding: 25px;
        box-sizing: border-box;
        border-radius: 20px;
        background-color: #fff;
        margin-bottom: 20px;
        &:last-child {
          margin-bottom: 0;
        }
        &-msg {
          width: 100%;
          // display: flex;
          // flex-direction: row;
          // flex-wrap: nowrap;
          // justify-content: space-between;
          
          .pritit {
            width: 100%;
            position: relative;
            &-title {
              width: 77%;
              font-size: 28px;
              font-weight: bold;
              min-height: 40px;
              @include lineClamp(28px, 1.4, 1);
            }
            &-price {
              padding-top: 20px;
              font-size: 22px;
              color: #333;
              width: 100%;
              &>span {
                margin-right: 20px;
                &:nth-child(1) {
                  text-decoration: line-through;
                  font-weight: 500;
                  color: #999;
                }
                &:last-child {
                  margin-right: 0;
                  &>i {
                    font-family: Alibaba-PuHuiTi;
                    font-size: 24px;
                    margin-right: 6px;
                    font-weight: 500;
                  }
                  &>em {
                    font-family: Alibaba-PuHuiTi;
                    font-size: 28px;
                    font-weight: 500;
                  }
                }
              }
            }
          }
          .btn {
            position: absolute;
            top: 50%;
            right: 0px;
            transform: translate(0, -50%);
            &-buy{
              color: #fff;
              line-height: 24px;
              font-size: 22px;
              font-weight: 500;
              padding: 12px 21px;
              border-radius: 26px;
              background:linear-gradient(-90deg,rgba(233,1,3,1),rgba(253,27,73,1));
            }
          }
        }
        &-img {
          padding-top: 20px;
          position: relative;
          display: flex;
          flex-direction: row;
          flex-wrap: nowrap;
          justify-content: space-between;
          &>ul {
            display: flex;
            flex-direction: row;
            flex-wrap: nowrap;
            justify-content: flex-start;
            &>li {
              width: 136px;
              height: 136px;
              margin-right: 20px;
              &>img {
                width: 100%;
                height: 100%;
                border-radius: 10px;
              }
            }
          }
          .item-count {
            position: absolute;
            top: 50%;
            right: 0;
            transform: translate(0, -50%);
            &>span {
              font-size: 28px;
              color: #666;
              &:last-child {
                margin-left: 25px;
              }
              &>em {
                color: #333;
                font-weight: bold;
              }
              &>img {
                width: 32px;
                height: 8px;
                vertical-align: 4px;
              }
            }
          }
        }
      }
    }
  }
</style>
